'''
Created on Jul 4, 2011

@author: vakumar
'''
from com.utils.util import Utils
from random import random
from com.sorts.sorter import Sorter
from copy import deepcopy

def comparision(test = 100, s_limit = 100):
    res = []
    rep = []
    m = Sorter.getsorter(Sorter._MERGE, None)
    q = Sorter.getsorter(Sorter._QUICK, None)
    for i in range(test):
        size = int(random()*s_limit)
        if i == test - 1 : size = s_limit
        arr = Utils.getrandomintlist(size)
        m.arr = arr
        m.sort()
        q.arr = arr
        q.sort()
        rep.append((m.count,q.count))
        if m.getComparisonCount() < q.getComparisonCount():
            res.append('m')
        elif m.count == q.count:
            res.append('eq')
        else:
            res.append('q')
    print '*'*20
    print '::Comparision::'
    print '*'*20        
    print 'total %s test performed::' %test
    print 'Merge Sort performs better in %s cases. While Quick Sort won in %s cases.' %(res.count('m'), res.count('q'))
    print 'Rest %s cases both performs equally...' %(res.count('eq'))
    print rep

def main():
    arr = Utils.getrandomintlist(16)
    #arr.reverse()
    m = Sorter.getsorter(Sorter._MERGE, arr)
    m.dosort()
    qarr = deepcopy(arr)
    q = Sorter.getsorter(Sorter._QUICK, qarr)
    q.dosort()
    harr = deepcopy(arr)
    h = Sorter.getsorter(Sorter._HEAP,harr)
    h.dosort()
    #comparision(test = 1, s_limit = 1000000)


if __name__ == '__main__':
    main()